package com.usefullc.english.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.usefullc.common.util.BeanUtils;
import com.usefullc.english.domain.Tag;
import com.usefullc.english.mapper.TagMapper;
import com.usefullc.english.query.TagQuery;
import com.usefullc.english.vo.TagVo;
import com.usefullc.system.entity.Pager;
import com.usefullc.system.service.AbstractBizService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 标签服务类
 * @author: 星空
 * @date: 2022-08-07
 */
@Service
public class TagService extends AbstractBizService<TagMapper, Tag, TagQuery> {


    @Override
    protected QueryWrapper<Tag> getQueryWrapper(TagQuery query) {
        QueryWrapper<Tag> queryWrapper = super.getQueryWrapper(query);
        return queryWrapper;
    }

    public Pager<TagVo> findVoByPage(TagQuery query){
        Pager<Tag> page = this.findByPage(query);
        Pager<TagVo> newPage = new Pager<>(page);
        List<Tag> dataList = page.getDataList();
        List<TagVo> newDataList = new ArrayList<>();
        newPage.setDataList(newDataList);
        for (Tag tag : dataList) {
            TagVo tagVo = BeanUtils.beanCopy(tag, TagVo.class);
            newDataList.add(tagVo);
        }
        return newPage;
    }


    public Tag findByTagName(String tagName){
        TagQuery query = new TagQuery();
        query.setName(tagName);
        return this.findOne(query);
    }


}
